'''
Created on Mar 21, 2013

@author: Jason
'''
from SimPy.Simulation import *
from Globals import Globals
from Server import Server
from EmailPacket import EmailPacket
from TelnetPacket import TelnetPacket
from VoicePacket import VoicePacket
from FTPPacket import FTPPacket

class Users(Process):
    CreationRate = 1.0
    
    def __init__(self):
        Process.__init__(self)
        
    def Run(self):
        while 1:
            yield hold,self,Globals.Rnd.expovariate(Users.CreationRate)
            
            packetType = Globals.Rnd.random()
        
            if packetType < Globals.TelnetRate:
                packet = TelnetPacket()
            elif packetType < (Globals.TelnetRate + Globals.EmailRate):
                packet = EmailPacket()
            elif packetType < (Globals.TelnetRate + Globals.EmailRate + Globals.VoiceRate):
                packet = VoicePacket()
            else:
                packet = FTPPacket()
            
            Server.bestEffortQueue.append(packet)
            print 'Adding packet'
            reactivate(Server.Servers[0])           